/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.DragonPokerServer.Thread.ServerRequest;


import java.util.ArrayList;
import org.DragonPokerServer.dbclasses.User;
import org.Comunicator.Element;
import org.Comunicator.Global;
import org.Comunicator.Message;
import org.DragonPokerServer.Thread.ThreadUser;
import org.DragonPokerServer.dbclasses.Room;

/**
 *
 * @author davide
 */
public class RoomsRequest extends GenericServerRequest{

    @Override
    public void processRequest(Message message, ThreadUser user) {
        System.out.println("SERVER-Rooms");

        Message reply = new Message();
        reply.setAction("RoomsReply");
        reply.getReceiver().add(user.getUser().getUsername());
        for(Room r: Global.rooms){
            ArrayList a = new ArrayList();
            a.add(r.getId());
            a.add(r.getName());
            reply.getParameters().add(new Element("Room", a));
            //reply.getParameters().add(new Element("Name", r.getName()));
        }
        Global.messages.addMessageToSend(reply);
    }

    @Override
    public boolean isToProcessing(Message message, ThreadUser user) {
        if("Rooms".equals(message.getAction()) == true)
            return true;
        else
            setNext(new PlayersInRoomRequest());
        return false;
    }

}
